# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=rav1e
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.3
pkgrel=3
pkgdesc='An AV1 encoder focused on speed and safety (mingw-w64)'
arch=('any')
url=https://github.com/xiph/rav1e/
license=(BSD)
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-nasm"
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-cargo-c"
)
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/xiph/rav1e/archive/v${pkgver}.tar.gz")
sha256sums=('a091f3387055e472b6e028aa013cf0f37fb5acce9f4db2605d929bbffb448d01')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo fetch \
    --locked
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo build \
    --release \
    --frozen \
    --offline

  cargo capi build \
    --release \
    --frozen \
    --library-type=cdylib
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo test \
    --release \
    --frozen
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo install \
    --frozen \
    --offline \
    --no-track \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  MSYS2_ARG_CONV_EXCL="--prefix=;" \
  cargo capi install \
    --release \
    --frozen \
    --library-type=cdylib \
    --prefix="${MINGW_PREFIX}" \
    --destdir="${pkgdir}"

  install -Dm644 LICENSE PATENTS -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
